<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>listChannels.c</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="kvaser.gif"/></td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('list_channels_8c-example.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">listChannels.c</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment">**             Copyright 2017-2018 by Kvaser AB, Molndal, Sweden</span></div><div class="line"><span class="comment">**                         http://www.kvaser.com</span></div><div class="line"><span class="comment">**</span></div><div class="line"><span class="comment">** This software is dual licensed under the following two licenses:</span></div><div class="line"><span class="comment">** BSD-new and GPLv2. You may use either one. See the included</span></div><div class="line"><span class="comment">** COPYING file for details.</span></div><div class="line"><span class="comment">**</span></div><div class="line"><span class="comment">** License: BSD-new</span></div><div class="line"><span class="comment">** ==============================================================================</span></div><div class="line"><span class="comment">** Redistribution and use in source and binary forms, with or without</span></div><div class="line"><span class="comment">** modification, are permitted provided that the following conditions are met:</span></div><div class="line"><span class="comment">**     * Redistributions of source code must retain the above copyright</span></div><div class="line"><span class="comment">**       notice, this list of conditions and the following disclaimer.</span></div><div class="line"><span class="comment">**     * Redistributions in binary form must reproduce the above copyright</span></div><div class="line"><span class="comment">**       notice, this list of conditions and the following disclaimer in the</span></div><div class="line"><span class="comment">**       documentation and/or other materials provided with the distribution.</span></div><div class="line"><span class="comment">**     * Neither the name of the &lt;organization&gt; nor the</span></div><div class="line"><span class="comment">**       names of its contributors may be used to endorse or promote products</span></div><div class="line"><span class="comment">**       derived from this software without specific prior written permission.</span></div><div class="line"><span class="comment">**</span></div><div class="line"><span class="comment">** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot;</span></div><div class="line"><span class="comment">** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE</span></div><div class="line"><span class="comment">** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE</span></div><div class="line"><span class="comment">** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE</span></div><div class="line"><span class="comment">** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR</span></div><div class="line"><span class="comment">** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF</span></div><div class="line"><span class="comment">** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR</span></div><div class="line"><span class="comment">** BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER</span></div><div class="line"><span class="comment">** IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)</span></div><div class="line"><span class="comment">** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE</span></div><div class="line"><span class="comment">** POSSIBILITY OF SUCH DAMAGE.</span></div><div class="line"><span class="comment">**</span></div><div class="line"><span class="comment">**</span></div><div class="line"><span class="comment">** License: GPLv2</span></div><div class="line"><span class="comment">** ==============================================================================</span></div><div class="line"><span class="comment">** This program is free software; you can redistribute it and/or modify</span></div><div class="line"><span class="comment">** it under the terms of the GNU General Public License as published by</span></div><div class="line"><span class="comment">** the Free Software Foundation; either version 2 of the License, or</span></div><div class="line"><span class="comment">** (at your option) any later version.</span></div><div class="line"><span class="comment">**</span></div><div class="line"><span class="comment">** This program is distributed in the hope that it will be useful,</span></div><div class="line"><span class="comment">** but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div><div class="line"><span class="comment">** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span></div><div class="line"><span class="comment">** GNU General Public License for more details.</span></div><div class="line"><span class="comment">**</span></div><div class="line"><span class="comment">** You should have received a copy of the GNU General Public License</span></div><div class="line"><span class="comment">** along with this program; if not, write to the Free Software</span></div><div class="line"><span class="comment">** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA</span></div><div class="line"><span class="comment">**</span></div><div class="line"><span class="comment">**</span></div><div class="line"><span class="comment">** IMPORTANT NOTICE:</span></div><div class="line"><span class="comment">** ==============================================================================</span></div><div class="line"><span class="comment">** This source code is made available for free, as an open license, by Kvaser AB,</span></div><div class="line"><span class="comment">** for use with its applications. Kvaser AB does not accept any liability</span></div><div class="line"><span class="comment">** whatsoever for any third party patent or other immaterial property rights</span></div><div class="line"><span class="comment">** violations that may result from any usage of this source code, regardless of</span></div><div class="line"><span class="comment">** the combination of source code and various applications that it can be used</span></div><div class="line"><span class="comment">** in, or with.</span></div><div class="line"><span class="comment">**</span></div><div class="line"><span class="comment">** -----------------------------------------------------------------------------</span></div><div class="line"><span class="comment">*/</span></div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * Kvaser Linux Canlib</span></div><div class="line"><span class="comment"> * List available channels</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="canlib_8h.html">canlib.h</a>&quot;</span></div><div class="line"><span class="preprocessor">#include &lt;stdio.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;string.h&gt;</span></div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> check(<span class="keywordtype">char</span>* <span class="keywordtype">id</span>, <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7">canStatus</a> stat)</div><div class="line">{</div><div class="line">  <span class="keywordflow">if</span> (stat != <a name="a0"></a><a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7a49743d0d438957118b9c6af2e831b209">canOK</a>) {</div><div class="line">    <span class="keywordtype">char</span> buf[50];</div><div class="line">    buf[0] = <span class="charliteral">&#39;\0&#39;</span>;</div><div class="line">    <a name="a1"></a><a class="code" href="group__can__general.html#ga01a7a415c95c579750bcdd95a1d245c4">canGetErrorText</a>(stat, buf, <span class="keyword">sizeof</span>(buf));</div><div class="line">    printf(<span class="stringliteral">&quot;%s: failed, stat=%d (%s)\n&quot;</span>, <span class="keywordtype">id</span>, (<span class="keywordtype">int</span>)stat, buf);</div><div class="line">  }</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>* argv[])</div><div class="line">{</div><div class="line">  <span class="keywordtype">int</span> chanCount = 0;</div><div class="line">  <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7">canStatus</a> stat;</div><div class="line">  <span class="keywordtype">int</span> i;</div><div class="line">  <span class="keywordtype">int</span> beta;</div><div class="line">  <span class="keywordtype">char</span> betaString[10];</div><div class="line">  <span class="keywordtype">char</span> name[256];</div><div class="line">  <span class="keywordtype">char</span> driverName[256];</div><div class="line">  <span class="keywordtype">char</span> custChanName[40];</div><div class="line">  <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> ean[2], fw[2], serial[2];</div><div class="line">  <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> canlibVersion;</div><div class="line">  uint16_t fileVersion[4];</div><div class="line"></div><div class="line">  (void)argc; <span class="comment">// Unused.</span></div><div class="line">  (void)argv; <span class="comment">// Unused.</span></div><div class="line"></div><div class="line">  <a name="a2"></a><a class="code" href="group__can__general.html#gaff1ec1d3416d3bdd56336a7b9ac008b1">canInitializeLibrary</a>();</div><div class="line"></div><div class="line">  beta = <a name="a3"></a><a class="code" href="group__can__general.html#ga0803bc56e8695150563a48df2c14db5f">canGetVersionEx</a>(<a name="a4"></a><a class="code" href="canlib_8h.html#a31271de29b51d610db6242e43e5a71f0">canVERSION_CANLIB32_BETA</a>);</div><div class="line">  <span class="keywordflow">if</span> (beta) {</div><div class="line">    sprintf(betaString, <span class="stringliteral">&quot;BETA&quot;</span>);</div><div class="line">  }</div><div class="line">  <span class="keywordflow">else</span> {</div><div class="line">    betaString[0] = <span class="charliteral">&#39;\0&#39;</span>;</div><div class="line">  }</div><div class="line">  canlibVersion = <a class="code" href="group__can__general.html#ga0803bc56e8695150563a48df2c14db5f">canGetVersionEx</a>(<a name="a5"></a><a class="code" href="canlib_8h.html#a8d72028015110e384b36efab7f847542">canVERSION_CANLIB32_PRODVER</a>);</div><div class="line">  printf(<span class="stringliteral">&quot;CANlib version %d.%d %s\n&quot;</span>,</div><div class="line">         canlibVersion &gt;&gt; 8,</div><div class="line">         canlibVersion &amp; 0xff,</div><div class="line">         betaString);</div><div class="line"></div><div class="line">  memset(name, 0, <span class="keyword">sizeof</span>(name));</div><div class="line">  memset(custChanName, 0, <span class="keyword">sizeof</span>(custChanName));</div><div class="line">  memset(ean, 0, <span class="keyword">sizeof</span>(ean));</div><div class="line">  memset(fw, 0, <span class="keyword">sizeof</span>(fw));</div><div class="line">  memset(serial, 0, <span class="keyword">sizeof</span>(serial));</div><div class="line"></div><div class="line">  stat = <a name="a6"></a><a class="code" href="group__can__general.html#ga65169ca633cd30aa92b8a80e28a5378b">canGetNumberOfChannels</a>(&amp;chanCount);</div><div class="line">  <span class="keywordflow">if</span> (stat != <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7a49743d0d438957118b9c6af2e831b209">canOK</a>) {</div><div class="line">    check(<span class="stringliteral">&quot;canGetNumberOfChannels&quot;</span>, stat);</div><div class="line">    exit(1);</div><div class="line">  }</div><div class="line">  printf(<span class="stringliteral">&quot;Found %d channel(s).\n&quot;</span>, chanCount);</div><div class="line"></div><div class="line">  <span class="keywordflow">for</span> (i = 0; i &lt; chanCount; i++) {</div><div class="line"></div><div class="line">    stat = <a name="a7"></a><a class="code" href="group__can__general.html#gab9552d1a588b0dbc144b097acba017b2">canGetChannelData</a>(i, <a name="a8"></a><a class="code" href="canlib_8h.html#ae0493f8c23dedb0e714421d44cd2e786">canCHANNELDATA_DRIVER_NAME</a>,</div><div class="line">                             &amp;driverName, <span class="keyword">sizeof</span>(driverName));</div><div class="line">    <span class="keywordflow">if</span> (stat != <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7a49743d0d438957118b9c6af2e831b209">canOK</a>) {</div><div class="line">      check(<span class="stringliteral">&quot;canGetChannelData: DRIVER_NAME&quot;</span>, stat);</div><div class="line">      exit(1);</div><div class="line">    }</div><div class="line"></div><div class="line">    stat = <a class="code" href="group__can__general.html#gab9552d1a588b0dbc144b097acba017b2">canGetChannelData</a>(i, <a name="a9"></a><a class="code" href="canlib_8h.html#a997726b7bdbe1fbe1b440f8e7cfc410d">canCHANNELDATA_DLL_FILE_VERSION</a>,</div><div class="line">                             &amp;fileVersion, <span class="keyword">sizeof</span>(fileVersion));</div><div class="line">    <span class="keywordflow">if</span> (stat != <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7a49743d0d438957118b9c6af2e831b209">canOK</a>) {</div><div class="line">      check(<span class="stringliteral">&quot;canGetChannelData: DLL_FILE_VERSION&quot;</span>, stat);</div><div class="line">      exit(1);</div><div class="line">    }</div><div class="line">    stat = <a class="code" href="group__can__general.html#gab9552d1a588b0dbc144b097acba017b2">canGetChannelData</a>(i, <a name="a10"></a><a class="code" href="canlib_8h.html#afc7edc82e3d370444c3b83c66a9c6479">canCHANNELDATA_DEVDESCR_ASCII</a>,</div><div class="line">                             &amp;name, <span class="keyword">sizeof</span>(name));</div><div class="line">    <span class="keywordflow">if</span> (stat != <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7a49743d0d438957118b9c6af2e831b209">canOK</a>) {</div><div class="line">      check(<span class="stringliteral">&quot;canGetChannelData: DEVDESCR_ASCII&quot;</span>, stat);</div><div class="line">      exit(1);</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="keywordflow">if</span> (strcmp(name, <span class="stringliteral">&quot;Kvaser Unknown&quot;</span>) == 0) {</div><div class="line">      stat = <a class="code" href="group__can__general.html#gab9552d1a588b0dbc144b097acba017b2">canGetChannelData</a>(i, <a name="a11"></a><a class="code" href="canlib_8h.html#aa4fc3066c84e718b90e870103837259b">canCHANNELDATA_CHANNEL_NAME</a>,</div><div class="line">                               &amp;name, <span class="keyword">sizeof</span>(name));</div><div class="line">      <span class="keywordflow">if</span> (stat != <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7a49743d0d438957118b9c6af2e831b209">canOK</a>) {</div><div class="line">        check(<span class="stringliteral">&quot;canGetChannelData: CHANNEL_NAME&quot;</span>, stat);</div><div class="line">        exit(1);</div><div class="line">      }</div><div class="line">    }</div><div class="line"></div><div class="line">    stat = <a class="code" href="group__can__general.html#gab9552d1a588b0dbc144b097acba017b2">canGetChannelData</a>(i, <a name="a12"></a><a class="code" href="canlib_8h.html#a9062beaa59d9787667bac6cbbc6b4e20">canCHANNELDATA_CARD_UPC_NO</a>,</div><div class="line">                             &amp;ean, <span class="keyword">sizeof</span>(ean));</div><div class="line">    <span class="keywordflow">if</span> (stat != <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7a49743d0d438957118b9c6af2e831b209">canOK</a>) {</div><div class="line">      check(<span class="stringliteral">&quot;canGetChannelData: CARD_UPC_NO&quot;</span>, stat);</div><div class="line">      exit(1);</div><div class="line">    }</div><div class="line"></div><div class="line">    stat = <a class="code" href="group__can__general.html#gab9552d1a588b0dbc144b097acba017b2">canGetChannelData</a>(i, <a name="a13"></a><a class="code" href="canlib_8h.html#a8b3b4903a766565c95afd7c90f76d994">canCHANNELDATA_CARD_SERIAL_NO</a>,</div><div class="line">                             &amp;serial, <span class="keyword">sizeof</span>(serial));</div><div class="line">    <span class="keywordflow">if</span> (stat != <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7a49743d0d438957118b9c6af2e831b209">canOK</a>) {</div><div class="line">      check(<span class="stringliteral">&quot;canGetChannelData: CARD_SERIAL_NO&quot;</span>, stat);</div><div class="line">      exit(1);</div><div class="line">    }</div><div class="line"></div><div class="line">    stat = <a class="code" href="group__can__general.html#gab9552d1a588b0dbc144b097acba017b2">canGetChannelData</a>(i, <a name="a14"></a><a class="code" href="canlib_8h.html#a1ab7e59c0771f2f9850e8fe1d2d58ff1">canCHANNELDATA_CARD_FIRMWARE_REV</a>,</div><div class="line">                             &amp;fw, <span class="keyword">sizeof</span>(fw));</div><div class="line">    <span class="keywordflow">if</span> (stat != <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7a49743d0d438957118b9c6af2e831b209">canOK</a>) {</div><div class="line">      check(<span class="stringliteral">&quot;canGetChannelData: CARD_FIRMWARE_REV&quot;</span>, stat);</div><div class="line">      exit(1);</div><div class="line">    }</div><div class="line"></div><div class="line">    (void) <a class="code" href="group__can__general.html#gab9552d1a588b0dbc144b097acba017b2">canGetChannelData</a>(i, <a name="a15"></a><a class="code" href="canlib_8h.html#a0e91dd0d999b3043c6da5cb911dd83d8">canCHANNELDATA_CUST_CHANNEL_NAME</a>,</div><div class="line">                             custChanName, <span class="keyword">sizeof</span>(custChanName));</div><div class="line"></div><div class="line">    printf(<span class="stringliteral">&quot;ch %2.1d: %-35s\t%x-%05x-%05x-%x, s/n %u, v%u.%u.%u %s (%s v%d.%d.%d)\n&quot;</span>,</div><div class="line">           i, name,</div><div class="line">           (ean[1] &gt;&gt; 12), ((ean[1] &amp; 0xfff) &lt;&lt; 8) | ((ean[0] &gt;&gt; 24) &amp; 0xff),</div><div class="line">           (ean[0] &gt;&gt; 4) &amp; 0xfffff, (ean[0] &amp; 0x0f),</div><div class="line">           serial[0],</div><div class="line">           fw[1] &gt;&gt; 16, fw[1] &amp; 0xffff, fw[0] &amp; 0xffff,</div><div class="line">           custChanName,</div><div class="line">           driverName, fileVersion[3], fileVersion[2], fileVersion[1]);</div><div class="line">  }</div><div class="line"></div><div class="line">  stat = <a name="a16"></a><a class="code" href="group__can__general.html#ga0d1c0e54ea20c3e3b328a32eb10c7b47">canUnloadLibrary</a>();</div><div class="line">  <span class="keywordflow">if</span> (stat != <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7a49743d0d438957118b9c6af2e831b209">canOK</a>) {</div><div class="line">    check(<span class="stringliteral">&quot;canUnloadLibrary&quot;</span>, stat);</div><div class="line">    exit(1);</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordflow">return</span> 0;</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- HTML footer for doxygen 1.8.13-->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer"> (canlib 5.38) Tue Feb 15 2022</li>
  </ul>
</div>
</body>
</html>
